//
//  DWRequstNetworkPrintPlugin.swift
//  DWSwift
//
//  Created by GDL on 2025/6/23.
//

import Moya
import Foundation
import DWCoreLib


// Sources/Networking/NetworkPlugin.swift
public struct DWRequstNetworkPrintPlugin: PluginType {
    public func prepare(_ request: URLRequest, target: TargetType) -> URLRequest {
        #if DEBUG
        print("URL:\(target.baseURL.absoluteString),Method:\(target.method),Path:\(target.path),Headers: \(request.headers)")
        #endif
        return request
    }
    
    public func didReceive(_ result: Result<Response, MoyaError>, target: TargetType) {
        switch result {
        case .success(let response):
#if DEBUG
            print("Response: \(String(data: response.data, encoding: .utf8) ?? "")")
#endif
        case .failure(let error):
#if DEBUG
            print("Error: \(error)")
#endif
        }
    }
}
